splitscreen ~ 12 splitscreen w1 logo w2init w1 Welcome to 4th_86 implementation of the FORTH language. It is recommended that you print out and read the file INTRO.4TH as this will explain the concept of FORTH as an operating environment. However -- if you prefer the "learn by doing" approach -- carry on with this tutorial. Use keysÿ4 F2ÿN andÿ4 F1ÿN to page forward and back. At the last page F2 will cycle you back to the beginning page. F1 action ceases at page 1. To leave 4th_86 and return to DOS type ÿ4 BYE ÿN $ ~ w1init w2 The blue window is used for tutorial text. The Brown window is for you to enter commands and view results. The power of 4th_86 lies in the "integrated development environment" FORTH as a language permits. Do not be discouraged initially by the "strange" symbols used -- or the "reverse" method of inputting variables and parameters. You will soon adapt to this as easily as you could to i++ and ++i or the perverse niceties of the semicolon in the C language -- or to the complex printf style formatting commands in Pascal; Fortran; or C. w2init w1 Try typing each of the following commands as you would if you were in MsDos **NOTE** although commands are shown in upper case ( capital ) letters you can type them in either upper or lower case. 4th_86 is not case sensitive. ÿ4 DIR ÿN ÿ4 DIR \*.SYS ÿN ÿ4 5 SECDELAY ÿN ÿ4 TM ÿN If you get in trouble -- use keys ÿ4 F2ÿN or ÿ4 F1ÿN to get back to the tutorial and try again w1 $ ~ w1init 13 w2 Now let's try two more forth WORDS which will give you some background details -- but will temporarily erase the colored windows. Do not panic when all the tutorial instructions disappear!! You can easily get them back by using keys ÿ4 F1 ÿ ÿ4 F2 ÿ -- or if that doesn't work, by typing ÿ4 HELP ÿ w2init w1 So let's try it --- type each of the following commands -- again just as you would if you were in MsDos ÿ4 INFO ÿN ÿ4 INTRO ÿN w1 $ ~ w2 2 Here is part of the the ÿ4 STATUS ÿ display w1 status $ ~ splitscreen w1init w2 When you are using 4th_86 seriously as a programming tool -- you will not usually be working in a colored window -- or half screen environment -- though you can if you so choose. In this exercise; once again all the tutorial text will disappear -- but this time ÿ4 F1 ÿ ÿ4 F2 ÿ will not function. Only ÿ4 HELP ÿ will return you to the tutorial text. w2init w1 Write down the following commands to try once you exit windowed mode ÿ4 DIR ÿN ÿ4 STATUS ÿN ÿ4 DDICT ÿN ÿ4 FILES ÿN ÿ4 DD GOTOXY ÿN ÿ4 DD SECDELAY ÿN Then type ÿ4 FULLSCREEN ÿN to leave tutorial mode. Remember -- enter ÿ4 HELP ÿN to return $ ~ w1init 10 w2 4th_86 also allows you to use your own favorite DOS editor with a considerable degree of automation. You will need to configure the file EDITR.BAT to make this work - so let's leave that till you've read INTRO.4TH. FORTH is both an INTERPRETER and a COMPILER. It's much much more than BASIC is -- but let's use the concepts of BASIC and C as a starting point. w1 C version Basic version --------- ------------- main(void) 10 for i = 1 to 10 { 20 print i int i; 30 next for (i=1; i<=10; i++ ) printf ("%d \n", i) ; Forth version } ------------- : test1 10 0 do i . crlf loop ; $ ~ w1init 9 w2 C version Basic version --------- ------------- main(void) 10 for i = 1 to 10 { 20 print i int i; 30 next for (i=1; i<=10; i++ ) printf ("%d \n", i) ; Forth version } ------------- : test1 10 0 do i . crlf loop ; w1 The C version has to be compiled and linked with a library to form an EXE file before the program can be executed. The file can be named TEST1.EXE. The BASIC version can be run in INTERPRETER mode by typing the command RUN. It can be saved as a file TEST1.BAS -- but this is not an executable file. If a COMPILER rather than an INTERPRETER is used -- an EXE file can be created -- but BASIC interpreters and compilers are separate utilities. The FORTH version is COMPILED **as it is being written**. It has a name TEST1 and can be immediately executed by typing TEST1. It can be saved either as an executable file TEST1.COM -- or source TEST1.4TH $ ~ split w2 9 You could now type in the following four FORTH definitions ÿ4: test1 5 0 do i . crlf loop ; ÿ ÿ4: test2 15 0 do i . tab 3 +loop ;ÿ ÿ4: test3 10 0 do i . 2 spcs loop ; ÿ ÿ4: test4 20 5 do i . loop ;ÿ However we have done it for you in a file called EXAMPLE1.4TH so all you need do is type ÿ4 FLOAD EXAMPLE1.4TH ÿ and then execute each word in turn by typing ÿ4TEST1ÿ ÿ4TEST2ÿ etc $ ~ split w1 23 Note that definitions can continue over several lines : test1 10 0 do i . crlf loop ; So that once you have entered a COLON sign -- 4th_86 will attempt to compile every statement you make -- up to the point at which it detects a SEMICOLON This causes few problems if you forget the semicolon -- because 4th_86 will rapidly be given some text it doesn't recognise -- at which point it will give an error message. w1 $ ~ split w1 23 The same applies to comment delimiters -- a CR does NOT end a comment. This can cause mysterious hangups as text you thought was being entered as a definition is being treated as an ongoing comment. : test5 20 0 do i . loop ; ( the above was test 5 : test6 15 0 do i . 3 +loop ; ( that was test 6 ) test5 has been entered as a definition. test6 however -- and any more text that is typed in -- is ignored by 4th_86 as a comment; because the right hand ) delimiter after " was test 5 " has been missed out. You must take care to ensure brackets match -- as do colons and semicolons. If 4th_86 appears to have gone to sleep -- it is most likely due to an unclosed comment string. w1 $ ~ w1init 10 w2 The same care must be taken to match double-quote marks " in strings Load the file EXAMPLE2 by typing ÿ4 FLOAD EXAMPLE2.4TH ÿ Once you have loaded the file try out the words ÿ4 HEADER ÿ ÿ4 FOOTER ÿ ÿ4 DOLOOP ÿ ÿ4 DOLOOPTEST ÿ As you have not yet configured EDITR.BAT -- you can use the command ÿ4 TYPE EXAMPLE2.4THÿ if you want to view the definitions again w1 $ ~ w1init 10 w2 Practice printing out some strings. It can be done in IMMEDIATE mode ( ie -- not within a word definition ) just as in BASIC. Take care to leave a space after the first quote mark " this is a test" ." will print correctly "this is a test" ." will give an error message w1 $ ~ w1init 10 w2 Note that control characters such as LF CR TAB etc can be inserted inline provided they are enclosed by up-arrow delimiters " this is ^9^ a test ^0dh 0ah^ to see ^13 10^ what happens " ." The 9 represents TAB. CR is either 0dh ( hex ) or 13 ( decimal ) LF is either 0ah ( hex) or 10 ( decimal) w1 $ ~ w2 2 Here are the definitions you've entered to date. ddict  $ ~ splitscreen w2 10 Go back to the previous screen and select a word somewhere in the middle of those listed under USER DEFINITIONS -- then return to this screen Let's suppose the word you chose was HEADER type ÿ4 FORGET HEADER ÿ and again return to the previous screen w1 You will find that HEADER and all the words defined after it have now been deleted from 4th_86. $ ~ splitscreen w2 19 Now let's define a new word -- type in ÿ4 : new-word " this is a test " ." ; ÿ you can make sure it works by typing ÿ4 new-word ÿ Now let's try to re-define the same word ÿ4 : new-word " this is not another test " ." ; ÿ when you get asked if you want to redefine -- answer Y Now test by again typing ÿ4 new-word ÿ type ÿ4 forget new-word ÿ and then ÿ4 new-word ÿ you will see that the original definition has been restored w1 $ ~ splitscreen w2 10 by now you should be reasonably comfortable with how 4th_86 functions ( see next screen for window manipulation commands ) repeat the last screen if unsure -- and then type ÿ4 w2 ÿ followed by ÿ4 splitat 0 ÿ and ÿ4 ddict ÿ w1 Now define and redefine some words -- use DDICT to examine the dictionary -- FORGET some words and use DDICT again. If you're feeling really brave, leave thhis tutorial by typing ÿ4 fullscreen ÿN and enjoy the freedom of a full size screen. Configure EDITR.BAT and ASMBL.BAT and work through the examples in the documentation. You can always return to windowed mode by the words ÿ4 splitscreen ÿN or ÿ4 help ÿN w1 $ ~ splitscreen w2 10 W1 places cursor in upper window W2 places cursor in lower window W1INIT and W2INIT clear windows SPLIT divides windows equally mid-screen SPLITAT N divides windows at line N ( if N > 23 it's truncated to 23 ) SPLITSCREEN is the same as SPLIT FULLSCREEN is the same as UNSPLIT w1 The source code for the tutorial / windows is included as 7TUT04.4TH All source code is pure ascii and can be printed as-is or edited with any ASCII type editor. examine the code to get further ideas of how to use FORTH $